package com.demomaster.quickcompat.widget.dialog.adapter;

import android.content.Context;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.demomaster.quickcompat.R;
import com.demomaster.quickcompat.view.adapter.QuickRecyclerAdapter;
import com.demomaster.quickcompat.view.adapter.QuickViewHolder;

import java.util.List;

public class SheetAdapter<VH extends SheetAdapter.SheetViewHolder> extends QuickRecyclerAdapter<VH> {
    public List data;
    public Context context;
    public SheetAdapter(Context context, List data) {
        this.context = context;
        this.data = data;
    }

    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_quick_sheet_dialog, viewGroup, false);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        return (VH) new SheetViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final VH vhItem, int i) {
        vhItem.onBind(i,data);
    }

    @Override
    public int getItemCount() {
        return this.data.size();
    }

    public interface ViewHolderInterface{
        void onbind(int position,List data);
    }

//    public static abstract class ViewHolder extends RecyclerView.ViewHolder implements ViewHolderInterface {
//
//        public ViewHolder(@NonNull View itemView) {
//            super(itemView);
//        }
//    }

    public static class SheetViewHolder extends QuickViewHolder {
        public Context context;
        TextView textView;

        public SheetViewHolder(@NonNull View itemView) {
            super(itemView);
            context = itemView.getContext();
            textView = itemView.findViewById(R.id.tv_text);
            if (Build.VERSION.SDK_INT >= 19) {
                textView.setBackgroundResource(R.drawable.ripple_bg);
            }
        }

        @Override
        public void onBind(int position, List data) {
            textView.setText(data.get(position) + "");
        }
    }
}
